/************************************************************************/
/* ParticleVertex.h                                                     */
/************************************************************************/


#ifndef             __PARTICLEVERTEX_H__
#define             __PARTICLEVERTEX_H__

#if _MSC_VER > 1000
#pragma once
#endif
#include "lyuheader.h"

class CParticleVertexManager
{
    typedef std::vector<SParticleVertex>::iterator PART_ITER;

    public:
    CParticleVertexManager() : m_fLifeTime(4800.0f)
		, m_pd3dDevice(0), m_pVB(0), m_pTexture(0)
    { 
		D3DXMatrixIdentity(&m_matIdentity);
	}

    ~CParticleVertexManager(){ DeleteObjectDevice(); }

    HRESULT RestoreDeviceObjects(LPDIRECT3DDEVICE9 pDevice,
        VertexBufferItem* pVB);

    HRESULT Render(EFFECT_DATA& fxdata);
    HRESULT DeleteObjectDevice();
    HRESULT MakeTranslation(D3DXMATRIX matTrans);
	
    void Update(const float& fElapsedTime,
        EFFECT_DATA& fxdata, const D3DXVECTOR3& vMin, const D3DXVECTOR3& vMax);
	
    void AddColor(const float& fTickNum, const D3DXCOLOR& color)
    {
        m_EventList.AddToList(fTickNum, color);
    }
    D3DXCOLOR GetColor(const float& fTickNum)
    {
	    return m_EventList.GetColor(fTickNum);
    }
    float GetSize(const float& fTickNum)
    {
        return m_EventList.GetFactor(fTickNum);
    }
    void AddSize( const float& fTickNum, const float& fSize )
    {
        m_EventList.AddToList(fTickNum, fSize);
	}
	void DeleteEventList()
	{
		m_EventList.Clear();
	}

    public:
    void SetLifeTime(float data){ m_fLifeTime = data;}
    void SetFirstUpdate(bool data){ m_bFirstUpdate = data;}
    bool IsFirstUpdate(void){ return m_bFirstUpdate;}
    void DecodeEventScript(const char* strEventScript);
	void SetColorEvent( int count, D3DXCOLOR particleColor, int time, int sizeR );

    private:
    void SetRenderState(void);
    void RenewStrip(const float& fElapsedTime, EFFECT_DATA& fxdata);
    void GenerateNewStrip(EFFECT_DATA& fxdata,
        const D3DXVECTOR3& vMin, const D3DXVECTOR3& vMax);	
	
    private:
    bool m_bFirstUpdate;
	
    float m_fLifeTime;

    CEventList m_EventList;
    
    LPDIRECT3DDEVICE9 m_pd3dDevice;
    VertexBufferItem* m_pVB;
    TextureItem* m_pTexture;
    D3DXMATRIX m_matIdentity;
};

#endif          __PARTICLEVERTEX_H__
